//
//  ViewController.m
//  线程 练习
//
//  Created by dllo on 16/8/17.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSThread *thread = [NSThread currentThread];
    thread.name = @"sec";
    NSLog(@"%@", thread);

//
    double p = [thread threadPriority];
    NSLog(@"%lf", p);
    // 判断当前线程是否为主线程
    [NSThread isMainThread]; // 类方法判断
    [thread isMainThread]; // 对象方法判断
    // 无论在哪 直接获取主线程
    [NSThread mainThread];
    // 初始化方法创建一个线程 创建的这个线程必须要启动才能使用
//    NSThread *thread1 = [[NSThread alloc] initWithTarget:self selector:@selector(createOneThread) object:nil];
//       [thread1 start];
    [NSThread detachNewThreadSelector:@selector(newThread) toTarget:self withObject:nil];
    
    
    
}

- (void)newThread {
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://pic1.win4000.com/wallpaper/8/511ce1c9ee276.jpg"]];
    [self performSelectorOnMainThread:@selector(getMain:) withObject:data waitUntilDone:YES];
}

- (void)getMain:(id)object {
    self.picImageView.image = [UIImage imageWithData:object];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
